<?php
/**
 * 留言控制器
 *
 * @category     Shuxun Cms
 * @date         2015年10月18日
 * @author       Shuxun Team <kaiping.jiang@scshux.com>
 * @file         MessageController.php
 */
namespace Scshux\Front\Controllers;
use Scshux\Utils\JSON;
use Scshux\Mvc\SModel;
use Scshux\Utils\Uploader;
use Scshux\Mvc\SQuery;
use Scshux\Plugin\Wechat;
use Scshux\Utils\Helper;
use Scshux\Tag\SmartyTag;
use Scshux\Utils\Time;
use Scshux\Utils\Validate;
class MessageController extends  ControllerBase
{
	/**
	 * 在线留言
	 */
	public  function  saveAction()
	{
		//新增语言过滤
		$site_id = $this->getCore()->getSiteID();
		
		if($this->request->isPost())
		{
			$nickname  = $_REQUEST['nickname'];
			$phone     = $_REQUEST['phone'];
			$company   = $_REQUEST['company'];
			$address   = $_REQUEST['address'];
			$size   = $_REQUEST['size'];
			$ywtype   = $_REQUEST['ywtype'];
			if(empty($nickname) || empty($phone) || empty($company) || empty($address) || empty($size) || empty($ywtype)){
				$this->senJsMsg('请输入完整的内容!');
			}
			//验证电话格式
			if(!Validate::mobi($phone))
			{
				$this->senJsMsg('电话号码格式错误!');
			}
// 			$_REQUEST['size'] = implode(',', $_REQUEST['size']);
// 			$_REQUEST['ywtype'] = implode(',', $_REQUEST['ywtype']);
			$_REQUEST['site_id'] = $site_id;
			$postData = $_REQUEST;
			$postData['ip'] = Helper::getIP();
			$postData['created'] = Time::gmtime();
			$messageModel = new SModel('message');
			$messageModel->setData($postData);
			$messageModel->add();
			$this->senJsMsg('需求提交成功,我们将尽快与您联系!');

		}else{
			$this->redirect('');
		}
	}
}